//
//  MBCompetationContentCell.m
//  MiBaoTu
//
//  Created by admin on 16/11/11.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBCompetationDetailContentCell.h"

@interface MBCompetationDetailContentCell() {
    UIView              *_bgView;
    UILabel             *_numLb;
    UIImageView         *_headImgView;
    UILabel             *_babyNameLb;
    UILabel             *_contentLb;
    UIView              *_lineView;
}

@end
@implementation MBCompetationDetailContentCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self onCreateUI];
    }
    return self;
}

- (void)onCreateUI
{
    _bgView = [[UIView alloc]initWithFrame:CGRectZero];
    _bgView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_bgView];
    
    //序号
    _numLb = [[UILabel alloc]initWithFrame:CGRectZero];
    _numLb.textAlignment = NSTextAlignmentCenter;
    _numLb.textColor = UIColorFromHex(0x333333);
    _numLb.font = [UIFont boldSystemFontOfSize:15.f];
    [_bgView addSubview:_numLb];
    CGAffineTransform transform = CGAffineTransformMake(1, 0, tanf(-15 * (CGFloat)M_PI / 180), 1, 0, 0);
    _numLb.transform = transform;
    
    //头像
    _headImgView = [[UIImageView alloc]initWithFrame:CGRectZero];
    _headImgView.backgroundColor = [UIColor clearColor];
    _headImgView.layer.cornerRadius = 5.;
    _headImgView.layer.masksToBounds = YES;
    [_bgView addSubview:_headImgView];
    
    //名字
    _babyNameLb = [[UILabel alloc]initWithFrame:CGRectZero];
    _babyNameLb.textAlignment = NSTextAlignmentLeft;
    _babyNameLb.textColor = UIColorFromHex(0x333333);
    _babyNameLb.font = [UIFont systemFontOfSize:14.f];
    [_bgView addSubview:_babyNameLb];

    _contentLb = [[UILabel alloc]initWithFrame:CGRectZero];
    _contentLb.textAlignment = NSTextAlignmentLeft;
    _contentLb.textColor = UIColorFromHex(0x999999);
    _contentLb.font = [UIFont systemFontOfSize:12.f];
    _contentLb.numberOfLines = 2;
    [_bgView addSubview:_contentLb];
    if (ISIPAD) {
        _babyNameLb.font = [UIFont systemFontOfSize:30*PERCEN];
        _contentLb.font = [UIFont systemFontOfSize:26*PERCEN];
    }
    //分割线
    _lineView = [[UIView alloc]initWithFrame:CGRectZero];
    _lineView.backgroundColor = [UIColorFromHex(0xcccccc)colorWithAlphaComponent:.45] ;
    [_bgView addSubview:_lineView];
}

- (void)setIdString:(NSString *)idString
{
    _idString = idString;
    [self setNeedsLayout];
}

- (void)setDataDic:(NSDictionary *)dataDic
{
    _dataDic = dataDic;
    [self setNeedsLayout];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    if (!_dataDic) return;
    
    //value
    if (_idString) {
        if ([_idString intValue] == 0) {
            _numLb.textColor = UIColorFromHex(0xe95078);
            _numLb.text = @"冠军";
            
        }
        else if ([_idString intValue] == 1) {
            _numLb.textColor = UIColorFromHex(0xeb6fa7);
            _numLb.text = @"亚军";
        }
        if ([_idString intValue] == 2) {
            _numLb.textColor = UIColorFromHex(0xf7c658);
            _numLb.text = @"季军";
        }
        if ([_idString intValue] >= 3) {
            _numLb.textColor = UIColorFromHex(0x333333);
            _numLb.text = @"优秀";
        }
    }
    NSString *st = [_dataDic objectForKey:@"FaceImg"];
    if ([st isKindOfClass:[NSNull class]]) {
        _headImgView.image = [UIImage imageNamed:@"activity_bg"];
    } else {
        [_headImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,st]] placeholderImage:[UIImage imageNamed:@"activity_bg"]];
    }
    
    _babyNameLb.text = [NSString stringWithFormat:@"%@",[_dataDic objectForKey:@"NickName"]];
    
    NSString *Signature = [_dataDic objectForKey:@"Signature"];
    if ([Signature isKindOfClass:[NSNull class]]) {
        Signature = @"";
    }
    _contentLb.text = Signature;
    
    
    //frame
    _bgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 144*PERCEN);
    if (ISIPAD) {
        _bgView.height=180*PERCEN;
    }
    _numLb.frame = CGRectMake(10, 0, 64*PERCEN-10, _bgView.height);
    if (ISIPAD) {
        _numLb.frame = CGRectMake(460*PERCEN, 0, 64*PERCEN, _bgView.height);
    }
    _headImgView.frame = CGRectMake(_numLb.right, (_bgView.height-106*PERCEN)/2., 106*PERCEN, 106*PERCEN);
    if (ISIPAD) {
        _headImgView.frame = CGRectMake(_numLb.right+30*PERCEN, 20*PERCEN , 140*PERCEN, 140*PERCEN);
    }
    
    float juHeight = (_bgView.height-60)/4.;
    _babyNameLb.frame = CGRectMake(_headImgView.right+18*PERCEN, juHeight+3, 200, 20);
    if (ISIPAD) {
           _babyNameLb.frame = CGRectMake(_headImgView.right+20*PERCEN, juHeight+3, 400*PERCEN, 30*PERCEN);
    }
    _contentLb.frame = CGRectMake(_babyNameLb.left, _babyNameLb.bottom+juHeight,_babyNameLb.width, _babyNameLb.height);
    
    _lineView.frame = CGRectMake(0, _bgView.height-1, _bgView.width, 1);
}

@end
